package com.spring.tools;

import java.util.List;

import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;

/**
 * 
 * @author wojunyu
 *
 */
public class ValidatorResultHandler {
	public static Result handle(BindingResult result) {
		Result retVal = new Result();

		if (result.hasErrors()) {
			List<ObjectError> list = result.getAllErrors();
			ObjectError oe = list.get(0);
			retVal.setMsg(oe.getDefaultMessage());
			retVal.setStatus("0");
		} else {
			retVal.setStatus("1");
		}
		return retVal;
	}
}
